package com.spic.business.mountguard.controller;

import com.spic.business.mountguard.domain.LeadersigninConfig;
import com.spic.business.mountguard.service.ILeadersigninConfigService;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 上岗到位配置Controller
 *
 * @author yangjie
 * @date 2021-11-02
 */
@RestController
@RequestMapping("/mountguard/config")
public class LeadersigninConfigController extends BaseController
{
    @Autowired
    private ILeadersigninConfigService leadersigninConfigService;

    /**
     * 查询上岗到位配置列表
     */
    @PreAuthorize(hasPermi = "business/mountguard:config:list")
    @GetMapping("/list")
    public TableDataInfo list(LeadersigninConfig leadersigninConfig)
    {
        startPage();
        List<LeadersigninConfig> list = leadersigninConfigService.selectLeadersigninConfigList(leadersigninConfig);
        return getDataTable(list);
    }

    /**
     * 导出上岗到位配置列表
     */
    @PreAuthorize(hasPermi = "business/mountguard:config:export")
    @Log(title = "上岗到位配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LeadersigninConfig leadersigninConfig) throws IOException
    {
        List<LeadersigninConfig> list = leadersigninConfigService.selectLeadersigninConfigList(leadersigninConfig);
        ExcelUtil<LeadersigninConfig> util = new ExcelUtil<LeadersigninConfig>(LeadersigninConfig.class);
        util.exportExcel(response, list, "上岗到位配置数据");
    }

    /**
     * 获取上岗到位配置详细信息
     */
    @PreAuthorize(hasPermi = "business/mountguard:config:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(leadersigninConfigService.selectLeadersigninConfigById(id));
    }

    /**
     * 新增上岗到位配置
     */
    @PreAuthorize(hasPermi = "business/mountguard:config:add")
    @Log(title = "上岗到位配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LeadersigninConfig leadersigninConfig)
    {
        return toAjax(leadersigninConfigService.insertLeadersigninConfig(leadersigninConfig));
    }

    /**
     * 修改上岗到位配置
     */
    @PreAuthorize(hasPermi = "business/mountguard:config:edit")
    @Log(title = "上岗到位配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LeadersigninConfig leadersigninConfig)
    {
        return toAjax(leadersigninConfigService.updateLeadersigninConfig(leadersigninConfig));
    }

    /**
     * 删除上岗到位配置
     */
    @PreAuthorize(hasPermi = "business/mountguard:config:remove")
    @Log(title = "上岗到位配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(leadersigninConfigService.deleteLeadersigninConfigByIds(ids));
    }
}
